package sql;
import java.sql.*;

@SuppressWarnings({"Duplicates", "unused", "SqlNoDataSourceInspection", "SqlDialectInspection"})
public class student_sql {
    private static final String URL = "jdbc:h2:~/test;MODE=MYSQL;DB_CLOSE_DELAY=-1";
    private static final String URL_MEM = "jdbc:h2:mem:test;MODE=MYSQL;DB_CLOSE_DELAY=-1";
    private static final String URL_TCP = "jdbc:h2:tcp://localhost/~/test1;MODE=MYSQL;DB_CLOSE_DELAY=-1";
    private static final String URL_TCP_MEM = "jdbc:h2:tcp://localhost/mem:test1;MODE=MYSQL;DB_CLOSE_DELAY=-1";
    private static final String DRIVER = "org.h2.Driver";
    private static final String NAME = "sa";
    private static final String PASSWORD = "";

    public static void main(String[] args) {
        try (Connection conn = DriverManager.getConnection(URL, NAME, PASSWORD)) {

            Statement stmt = conn.createStatement();

            stmt.executeUpdate(
                    "CREATE TABLE IF NOT EXISTS `user` (" +
                            "  `id` int(11) unsigned NOT NULL AUTO_INCREMENT," +
                            "  `stuName` varchar (50) NOT NULL," +   //姓名
                            "  `stuNumber` varchar (100) NOT NULL," +      //学号
                            "  `stuAge` int(50) NOT NULL," +        //年龄
                            "  `stuSex` varchar (50) NOT NULL," +   //性别
                            "  `stuEmail` varchar (100) NOT NULL," +  //邮箱
                            "  `stuAddress` varchar (100) NOT NULL," +  //住址
                            "  PRIMARY KEY (`id`)" +
                            ");"
            );

            stmt.executeUpdate(
                    "insert into `user` (`stuName`,`stuNumber`,`stuAge`,`stuSex`,`stuEmail`,`stuAddress`) values ('吴泽良', '201641413212',22,'男','582946945@qq.com','松山湖');"
            );

            ResultSet rs = stmt.executeQuery("select * from user");//选择import java.sql.ResultSet;


            while (rs.next()) {
                System.out.println(rs.getString("id") + "," + rs.getString("stuName") + "," + rs.getString("stuNumber") + "," + rs.getInt("stuAge")
                        + "," + rs.getString("stuSex")+ "," + rs.getString("stuEmail")+ "," + rs.getString("stuAddress"));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }



}
